package remato.domain.server.ejb;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.GenerationType.AUTO;
import static javax.persistence.InheritanceType.TABLE_PER_CLASS;

import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import remato.common.domain.helpers.ProjectParentable;
import remato.domain.common.Project;
import remato.domain.common.PropertySet;
import remato.domain.common.RequirementSystem;
import remato.domain.common.Stakeholder;
import remato.domain.common.Status;
import remato.domain.common.impl.RequirementSystemImpl;

import com.wgo.bpot.domain.common.User;
import com.wgo.bpot.domain.server.ejb.UserEjb;

@Entity
@Inheritance(strategy=TABLE_PER_CLASS)
public class RequirementSystemEjb extends RequirementSystemImpl implements RequirementSystem, ProjectParentable {
	
	@Override
	@Id
	@GeneratedValue(strategy=AUTO)
	public Long getDbId() {
		return super.getDbId();
	}
	
	/**
	 * This is a Unidirectional with join table, meaning the children
	 * (PropertySet) do not have a reference to the parent (RequirementSystem)
	 */
	@Override
	@OneToMany(targetEntity = PropertySetEjb.class, cascade = { ALL })
	@JoinColumn(name="requirementSystem")
	public Set<PropertySet> getPropertySets() {
		return super.getPropertySets();
	}

	/**
	 * This is a Unidirectional with join table, meaning the children
	 * (Project) do not have a reference to the parent (RequirementSystem)
	 */
	@Override
	@OneToMany(targetEntity = ProjectEjb.class, cascade = { ALL })
	@JoinColumn(name="requirementSystem")
	public Set<Project> getProjectChildren() {
		return super.getProjectChildren();
	}

	/**
	 * This is a Unidirectional with join table, meaning the children
	 * (Stakeholder) do not have a reference to the parent (RequirementSystem)
	 */
	@Override
	@OneToMany(targetEntity = StakeholderEjb.class, cascade = { ALL })
	@JoinColumn(name="requirementSystem")
	public Set<Stakeholder> getStakeholders() {
		return super.getStakeholders();
	}
	
    @Override
    @OneToMany(targetEntity = StatusEjb.class, cascade = { ALL })
    @JoinColumn(name="requirementSystem")
    public List<Status> getRequirementStatuses(){
        return super.getRequirementStatuses();
    }
    
    @Override
    @OneToMany(targetEntity = UserEjb.class, cascade = { ALL })
    @JoinColumn(name="requirementSystem")
    public Set<User> getUsers() {
        return super.getUsers();
    }
    
	/**
	 * Needed to trigger CGLib proxy (ie. if other CGLib-proxies is used as 
	 * parameter.)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

}
